home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / system / mail / transpor / ifmail23.z / ifmail23 / ifmail / iflib / matchaka.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-10  |  1.1 KB  |  55 lines

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #include "ftn.h"
  4. #include "lutil.h"
  5. #include "config.h"
  6.  
  7. int metric(a1,a2)
  8. faddr *a1,*a2;
  9. {
  10.     if ((a1->domain != NULL) &&
  11.         (a2->domain != NULL) &&
  12.         (strcasecmp(a1->domain,a2->domain) != 0))
  13.         return METRIC_DOMAIN;
  14.     if ((a1->zone != 0) && (a2->zone != 0) &&
  15.         (a1->zone != a2->zone))  return METRIC_ZONE;
  16.     if (a1->net   != a2->net)   return METRIC_NET;
  17.     if (a1->node  != a2->node)  return METRIC_NODE;
  18.     if (a1->point != a2->point) return METRIC_POINT;
  19.     return METRIC_EQUAL;
  20. }
  21.  
  22. faddr *bestaka_s(addr)
  23. faddr *addr;
  24. {
  25.     fa_list *tmp;
  26.     faddr *best;
  27.     int minmetric,wt;
  28.  
  29.     debug(6,"bestaka_s for %s",ascfnode(addr,0x1f));
  30.     best=whoami->addr;
  31.     minmetric=metric(addr,best);
  32.     for (tmp=whoami;tmp;tmp=tmp->next)
  33.     if (((wt=metric(addr,tmp->addr)) < minmetric) &&
  34.         ((best->point != 0) || (wt > METRIC_POINT)))
  35.     {
  36.         minmetric=wt;
  37.         best=tmp->addr;
  38.     }
  39.     debug(6,"bestaka_s is  %s",ascfnode(best,0x1f));
  40.     return best;
  41. }
  42.  
  43. int is_local(addr)
  44. faddr *addr;
  45. {
  46.     fa_list *tmp;
  47.  
  48.     for (tmp=whoami;tmp;tmp=tmp->next)
  49.     {
  50.         if (metric(tmp->addr,addr) == METRIC_EQUAL)
  51.             return 1; /* yes */
  52.     }
  53.     return 0; /* no */
  54. }
  55.